package youleche.com.business;

import java.sql.Connection;
import java.util.List;

import youleche.com.common.IDFactory;
import youleche.com.connection.ConnectionFactory;
import youleche.com.factory.DaoFactory;
import youleche.com.idao.IFixInfo;
import youleche.com.model.MFixInfo;

/**
 * 修理信息业务类
 * @author Administrator
 *
 */
public class BFixInfo {
	/**
	 * 数据库连接
	 */
	private Connection con = null;
	
	/**
	 * 处理器
	 */
	private IFixInfo handler = null;
	
	/**
	 * 构造器
	 */
	public BFixInfo(){
		this.handler = DaoFactory.getDFixInfo();
	}
	
	/**
	 * 添加修理I信息
	 * @param fixInfo 修理信息
	 * @return 返回添加影响的行数
	 * @throws Exception 异常 
	 */
	public int addFixInfo(MFixInfo fixInfo) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			fixInfo.setFixId(IDFactory.getId("meileche", "fixInfo"));
			return this.handler.addFixInfo(this.con, fixInfo);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	/**
	 * 获取修理信息
	 * @param startIndex 开始索引
	 * @param endIndex 结束索引
	 * @return 返回修理信息
	 * @throws Exception 异常
	 */
	public List<MFixInfo> getFixInfos(String startIndex,
			String endIndex) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getFixInfos(this.con, startIndex, endIndex);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 用户置顶修理信息
	 * @param fixId 修理信息ID
	 * @return 返回影响的行数
	 * @throws Exception 异常
	 */
	public int topFixInfoById(String fixId) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			return this.handler.topFixInfoById(this.con, fixId);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 根据ID得到修理信息
	 * @param fixId 修理信息ID
	 * @return 返回修理信息
	 * @throws Exception 异常
	 */
	public MFixInfo getFixInfoById(String fixId)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getFixInfoById(this.con, fixId);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 得到用户的修理信息总数
	 * @param sellerId 用户ID
	 * @return 返回修理信息总数
	 * @throws Exception
	 */
	public String getFixInfoCountBySellerId(String sellerId)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getFixInfoCountBySellerId(this.con, sellerId);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 根据用户Id获取修理信息
	 * @param startIndex 开始索引
	 * @param endIndex 结束索引
	 * @param sellerId 用户ID
	 * @return 返回修理信息
	 * @throws Exception 异常
	 */
	public List<MFixInfo> getFixInfosBySellerId(String startIndex,
			String endIndex, String sellerId) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getFixInfosBySellerId(this.con, startIndex, endIndex ,sellerId);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
}
